import {
	defineStore
} from 'pinia'
import {
	ref
} from 'vue'
import {
	getGoodList
} from '../api/user.api.js'

export const useUserStore = defineStore(
	'user',
	() => {
		const goodListData = ref([]) // 商品列表数据
		

		// 获取商品列表数据
		const getGoodListData = async () => {
			let result = await getGoodList()
			goodListData.value = result.message
		}
		
		// 跳转用户页
		const goUser = () => {
			uni.switchTab({
				url: '/pages/user/user'
			})
		}
		
		return {
			goodListData,
			getGoodListData,
			goUser
		}
	}, {
		persist: {
			storage: {
				getItem(key) {
					return JSON.parse(uni.getStorageSync(key)); // 手动替代 destr
				},
				setItem(key, value) {
					uni.setStorageSync(key, JSON.stringify(value));
				},
			},
		}
	}
)